package com.privacy.accountmgr.views.numberpasswordview

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.widget.LinearLayout
import android.widget.TextView

class NumberView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)
    : LinearLayout(context, attrs, defStyleAttr) {
    init {
        init()
    }

    private fun init() {
        for (i in 0 until DEFAULT_PASSWORD_COUNT) {
            val textView = TextView(context)
            textView.textSize = 14f
            textView.setTextColor(Color.parseColor("#55ffffff"))
            textView.text = "●"
            textView.setPadding(18, 18, 18, 18)
            orientation = LinearLayout.HORIZONTAL
            addView(textView)
        }
    }

    fun setEnteredCount(count: Int) {
        for (i in 0 until DEFAULT_PASSWORD_COUNT) {
            val textView = getChildAt(i) as TextView
            if (i < count) {
                textView.setTextColor(Color.WHITE)
            } else {
                textView.setTextColor(Color.parseColor("#55ffffff"))
            }
        }
    }

    companion object {
        val DEFAULT_PASSWORD_COUNT = 4
    }
}
